<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
namespace Admin\Service;
/**
 * @todo 活动服务层
 * @author PHP@妖孽 <dino_ma@163.com>
 * @since 2015-8-17
 */
class ActivityService{

	 protected $error            =   '';

	/**
	 * @todo 活动报名
	 * @param $data array
	 * <li>@param activity_id int 活动id</li> 必填
	 * <li>@param mobile_phone string(11) 手机号</li> 必填
	 * <li>@param customer_name string(20) 姓名</li>
	 * @param type int 0,1 0默认已报名返回用户Id, 1,已报名返回提示信息
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function joinActivity($data,$type){
		$obj = D('Admin/Activity');
		if($customer_id = $obj->joinActivity($data,$type)){
			return $customer_id;
		}else{
			$this->error = $obj->getError();
			return false;
		}
	}


	/**
	 * @todo 获取活动的报名总人数
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function getActivityConsumer($activity_id){
		return D('Admin/ActivityJoin')->getActivityConsumer($activity_id);
	}

	/**
	 * @todo 获取活动报名列表
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function getActivityConsumerList($activity_id){
		return D('Admin/ActivityJoin')->getJoinList($activity_id,8);
	}
	/**
	 * @todo 获取线上/线下活动 list
	 * @param is_online int 1[线上活动]/0[线下活动]
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function getActivityList($is_online){
		$is_online = (int)$is_online;
		if($is_online !=0 && $is_online !=1){
			$this->error ='is_online参数有误';
			return false;
		}
		return D('Admin/Activity')->getActivityList($map=array('status'=>1,'parent_id'=>0,'is_online'=>$is_online),$order='sort desc',$field="activity_id,activity_name");
	}

	/**
	 * @todo   根据活动ID获取当前的活动HTML
	 * @param  activity_id int 活动ID 必填
	 * @author fang
	 */
	public function getActivityContent($activity_id){
	    $activity_id = (int)$activity_id;
	    if($activity_id == 0){
	        $this->error ='activity_id参数有误';
	        return false;
	    }
	    $result = D('Admin/Activity')->getActivityContent($activity_id);
	    if($result){
	        return $result;
	    }else{
	        $this->error = D('Admin/Activity')->getError();
	        return false;
	    }
	}

	/**
     * @todo 活动签到
     * @param activity_id 活动id
     * @param customer_id 用户id
     * @author PHP@妖孽 <dino_ma@163.com>
     */
// 	public function activitySign($activity_id,$customer_id){
// 	    $obj = D('Admin/Activity');
// 	    if($obj->activitySign($activity_id,$customer_id)){
// 	        return true;
// 	    }else{
// 	        $this->error = $obj->getError();
// 	        return false;
// 	    }
// 	}

	/**
	 * @todo 拉取活动中的外部报名数据(sign_channel 0,3,4的数据)
	 * @param activity_id 活动id
     * @param offset_id 偏移量
     * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function getActivityJoinPerson($activity_id,$offset_id){
		$obj = D('Admin/ActivityJoin');
		if($list = $obj->getActivityJoinPerson($activity_id,$offset_id)){
			return $list;
		}else{
			$this->error = $obj->getError();
			return false;
		}
	}


	/**
	 * @todo 用户是否报名过此次活动
	 * @param int activity_id 活动id
	 * @param int customer_id 用户id
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function checkCustomerIsJoinActivity($activity_id,$customer_id){
		$obj = D('Admin/Activity');
		if($join_info = $obj->checkCustomerIsJoinActivity($activity_id,$customer_id)){
			return $join_info;
		}else{
			$this->error = $obj->getError();
			return false;
		}
	}



	/**
	 * @todo 客服系统查看用户是否报名过此次活动
	 * @param int activity_id 活动id
	 * @param int customer_id 用户id
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function serviceCheckCustomerIsJoin($activity_id,$customer_id){
		return D('Admin/ActivityJoin')->checkCustomerIsJoinActivityByService($activity_id,$customer_id);
	}




	/**
     * @todo 客服系统通过手机号/用户id来报名某一个活动
     * @param array();
     *
     * <li>activity_id(int)</li>; 活动id 必须存在
     * <li>customer_id(int)</li>; 用户id 必须存在
     * <li>join_time (int10)</li>; 报名时间,如果不存在则设置 NOW_TIME
     * <li>sign_channel (int)</li>; 报名渠道只接收1和,2
     * <li>generalize_member_id (int)</li>; 推广人id 必须存在
     * <li>ticket_level (int)</li>; 票别 0,1
     * @param int or string(11) customer_id用户id
     * @authro PHP@妖孽 <dino_ma@163.com>
     */
	public function serviceCustomerJoinActivity($data){
		$obj = D('Admin/ActivityJoin');
		if($call_back = $obj->serviceCustomerJoinActivity($data)){
			return $call_back;
		}else{
			$this->error = $obj->getError();
			return false;
		}
	}

	/**
	 * @todo 客服系统转化的报名更改状态
	 * @param int activity_join_id 活动表报名主键
	 * @return bool true/false
	 * @authro PHP@妖孽 <dino_ma@163.com>
	 */
	public function isServiceChange($activity_join_id){
		$obj = D('Admin/ActivityJoin');
		if($call_back = $obj->isServiceChange($activity_join_id)){
			return $call_back;
		}else{
			$this->error = $obj->getError();
			return false;
		}
	}

	/**
	 * @todo 获取活动详细信息
	 */

	/**
	 * @todo 返回最后一次错误记录
	 * @return string
	 */
	public function getError(){
		return $this->error;
	}
}
